<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var maxProfit = function (prices) {
        let len = prices.length;
        if (len === 0) {
          return 0;
        }
        let maxProfit = 0;
        let minPrice = prices[0];
        for (let i = 0; i < len; i++) {
          if (prices[i] < minPrice) {
            minPrice = prices[i];
          } else if (prices[i] - minPrice > maxProfit) {
            maxProfit = prices[i] - minPrice;
          }
        }
        return maxProfit;
      };
    </script>
  </body>
</html>
